﻿using System;
using System.Windows;
using Mammoth.Events;
using Mammoth.Factories;
using Mammoth.Navigations;
using Mammoth.Services;
using Mammoth.ViewModels;
using Mammoth.Views;
using Mammoth.Views.Transaction;

namespace Mammoth
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow(ITypeFactory viewFactory, IViewModelFactory vmFactory)
        {
            InitializeComponent();

            AddHandler(RoutedEvents.MessageBoxEvent,
                new RoutedEventHandler<MessageBoxEventArgs>(MessageBoxEventHandler));

            var m = (EventList)viewFactory.CreateByType(typeof(EventList));
            Widget.Children.Add(m);

            //initialize viewmodel dilakukan karena navigation controller perlu reference tadi Container
            var vm = vmFactory.GetViewModel<MainWindowViewModel>(this);
            vm.NavigationService = new NavigationController(Container, viewFactory);
            vm.NavigationService.SetDefault(typeof(TransactionView));
            vm.Initialize();
            DataContext = vm;
        }

        public void MessageBoxEventHandler(object sender, MessageBoxEventArgs e)
        {
            e.Result = MessageBox.Show(e.Message, e.Title, e.Button);
        }

    }
}
